#if 0

#include "hal_flash.h"
#include "util.h"
#include "hal_dma.h"

#define		VERSION_ADDR	0x5000

char version[] = "1.0";

#else

#include "util.h"
#include "flash.h"
#include <string.h>
#include "demo_code.h"


__xdata BYTE outputdata[20] = {0};
const char inputdata[] = "Hello";

//__code const char code1_buf[10000]@0x58000 = {2, 3};
//__code const char code2_buf[10000]@0x68000 = {4, 5};
#endif

#if 0
__banked_func void app_code0() @0x4A000
{
	//TRACE("FMAP: %02x\r\n", FMAP);
	//TRACE("code0: %d\r\n", code0_buf[0]);
}

__banked_func void app_code1() //@0x5A000
{
	TRACE("code1: %d\r\n", code1_buf[0]);
}

__banked_func void app_code2() //@0x6A000
{
	TRACE("code2: %d\r\n", code2_buf[0]);
}
#endif


void demo_app()
{
#if 0
	char str[20];
	HalDmaInit();
	HalFlashErase(10);
	HalFlashWrite(VERSION_ADDR >> 2, version, 1);
	
	str[0] = *((char __code *)VERSION_ADDR);
	str[1] = *((char __code *)(VERSION_ADDR + 1));
	str[2] = *((char __code *)(VERSION_ADDR + 2));
	str[3] = 0;
	//strcpy(str, (char *)((char __code *)VERSION_ADDR));
	TRACE("Version: %s\r\n", str);
	while(1);
#else
	
	INT16 length = strlen(inputdata);
	//uint16 i;
	//char temp;
	
	INT32 flashAddress = 0x18000;
	FlashErase(flashAddress);
	FlashWrite((BYTE *)inputdata, flashAddress, length + 1);
	FlashRead(flashAddress, outputdata, length + 1);
	TRACE("Read from flash: %s\r\n", outputdata);
#if 0
	//for(i = 0; i < 2; i++)
	{
		TRACE("code0: %08x\r\n", code0_buf);
		TRACE("code1: %08x\r\n", code1_buf);
		TRACE("code2: %08x\r\n", code2_buf);
	}
#else
	demo1_code();
	demo2_code();
	//app_code0();
	//app_code1();
	//app_code2();
#endif
	while(1);
#endif
	
}